package dyn 
{
		import flash.display.BitmapData;
		import flash.display.Bitmap;
		import flash.display.Loader;
		import flash.events.Event;
		import flash.events.IOErrorEvent;
		import flash.net.URLLoader;
		import flash.net.URLRequest;
		import dyn.TileFamily;
	/**
	 * ...
	 * @author Excel Excel
	 */
	public class LazyLoad
	{
		private var tf:TileFamily;
		private var ss:String;
		private var ii:uint;
		public var done:Boolean;
		public var error:Boolean;
		public function LazyLoad(f:TileFamily, s:String, i:uint)
		{
			done = false;
			error = false;
			tf = f;
			ss = s;
			ii = i;
			var _URL:URLRequest = new URLRequest(s);
			var _Loader:Loader = new Loader();
			_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, bmpLoaded);
			_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, bmpLoadError);
			_Loader.load(_URL);
		}
		
		function bmpLoaded(event:Event)
		{
			done = true;
			var bitmap:Bitmap = event.target.loader.content as Bitmap;
			bitmap.smoothing = false;
			tf.bm.push(bitmap.bitmapData);
			tf.bn.push(ii);
			trace ("Successfully loaded tile ", ss);
		}
		
		function bmpLoadError(event:IOErrorEvent)
		{
			trace("Failed to load tile ", ss);
			error = true;
			throw (event.text);
		}
		
	}

}